package com.econ.powercloud.ems.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * 获取环境变量
 *
 * @author chenxiaoqi
 * @since 2021/07/28
 */
@Component
public class ProfileUtil implements ApplicationContextAware {

    private static ApplicationContext context = null;

    @Override
    public void setApplicationContext(@NonNull ApplicationContext applicationContext) {
        context = applicationContext;
    }

    /**
     * 获取当前环境参数  exp: local,dev,prod,test 等
     * @return
     */
    public static String getActiveProfile() {
        String[] profiles = context.getEnvironment().getActiveProfiles();
        if (profiles.length == 0) {
            return "";
        }
        return profiles[0];
    }
}
